// pages/index1/index1.js

var app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    loading: false,
    plain: false,
    disabled: false,
    sid:'',
    sname:'',
    nj: '',
    bj: '',
    sfzh: '',
    wxid: '',
    osfzh:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    var wxid = wx.getStorageSync('openid');
    this.setData({
      wxid: wxid
    })

    var sid = wx.getStorageSync('sid');
    this.setData({
      sid: sid
    })

    var nj = wx.getStorageSync('nj');
    this.setData({
      nj: nj
    })

    var bj = wx.getStorageSync('bj');
    this.setData({
      bj: bj
    })

    var sfzh = wx.getStorageSync('sfzh');
    this.setData({
      sfzh: sfzh
    })
    this.setData({
      osfzh: sfzh
    })
    
    var sname = wx.getStorageSync('sname');
    this.setData({
      sname: sname
    })

  },

  //输入姓名
  snameinput: function (e) {
    this.setData({
      sname: e.detail.value
    })
  },
  
  //输入年级
  njinput: function (e) {
    this.setData({
      nj: e.detail.value
    })
  },
  //输入班级
  bjinput: function (e) {
    this.setData({
      bj: e.detail.value
    })
  },
  //身份证号
  sfzhinput: function (e) {
    this.setData({
      sfzh: e.detail.value
    })
  },


  //账号修改
  uaccountlogin: function (e) {
    var sid = this.data.sid;
    var nj = this.data.nj;
    var bj = this.data.bj;
    var sfzh = this.data.sfzh;
    var sname = this.data.sname;
    if (sname == '') {
      wx.showModal({
        title: '友情提示',
        content: '请输入姓名!',
        showCancel: !1,
      })
    }
    if (nj == '') {
      wx.showModal({
        title: '友情提示',
        content: '请输入年级!',
        showCancel: !1,
      })
    }
    if (bj == '') {
      wx.showModal({
        title: '友情提示',
        content: '请输入班级!',
        showCancel: !1,
      })
    }
    if (sfzh == '') {
      wx.showModal({
        title: '友情提示',
        content: '请输入身份证号!',
        showCancel: !1,
      })
    }

    var djson = {
      sid: sid,
      sname: sname,
      nj: nj,
      bj: bj,
      sfzh: sfzh,
      osfzh: this.data.osfzh
    };

    var that = this;
    wx.request({
      url: app.myUlife.ulifeUrl + '/wechart/EditStudent.html',//请求地址
      data: djson,
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {

        wx.showModal({
          title: '友情提示',
          content: '信息修改成功，将跳转至首页!',
          showCancel: !1,
        })

        wx.removeStorageSync('nj');
        wx.removeStorageSync('bj');
        wx.removeStorageSync('sfzh');
        wx.removeStorageSync('sname');

        wx.setStorageSync('nj', djson.nj);//加入缓存
        wx.setStorageSync('bj', djson.bj);//加入缓存
        wx.setStorageSync('sfzh', djson.sfzh);//加入缓存
        wx.setStorageSync('sname', djson.sname);
        //跳转到首页
        wx.switchTab({
          url: '../../pages/home/home'
        })

      }
    })
   
  },

  

})
